//获取当前时间
function CurentTime() {
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var clock = year + " 年 ";
    if (month < 10)
        clock += "0";
    clock += month + " 月 ";
    if (day < 10)
        clock += "0";
    clock += day + " 日 ";
    return (clock);
}

function CurentHour() {
    var now = new Date();
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var clock = hh;
    if (hh < 10)
        clock += "0";
    clock = hh + " : ";
    if (mm < 10) clock += '0';
    clock += mm;
    return (clock);
}

let Index = {
    init() {
        let that = this;
        this.charts = {};
        this.loadData();
        Public.chartsResize(this.charts)
    },
    loadData() {
        $('.header-r time').html(CurentTime());
        $('.header-r span').html(CurentHour());
        this.ec01_line_trend_d();//数据走势
        this.ec02_line_globe_d();//地球
        this.ec03_line_tradetrend_d();
        this.ec04_line_exporttrend_d();
        this.ec05_line_importtrend_d();
        this.ec06_line_importtrend_d();
        this.ec07_line_importtrend_d();
        this.ec08_line_importtrend_d();
        this.ec09_line_importtrend_d();
        this.ec010_line_importtrend_d();
        this.ec011_line_importtrend_d();


    },
    ec01_line_trend_d() {
        let myChart = echarts.init($("#ec01_line_thecity")[0]);
        myChart.clear();
        myChart.setOption(com_lineBar_vertical);
        myChart.setOption({
            xAxis: [{
                    data: ['韩国', '新加坡', '印度',  '俄罗斯', '阿联酋','泰国', '波兰', '越南', '马来西亚', '土耳其'],
                }
            ],
            legend: {show: true,right:'10%',top:0},
            grid:{
              right:'12%',
              left:"8%"
            },
            yAxis : [
                {
                    min: 0,
                    max: 10000,
                    interval: 1000,

                },
                {
                    min: 0,
                    max: 12000,
                    interval: 3000,

                }
            ],
            series: [
                {
                    name: '出口额',
                    type: 'bar',
                    itemStyle: {
                        //柱子修改渐变颜色
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#227cff'
                            }, {
                                offset: 1,
                                color: '#4194ff'
                            }]),
                        }
                    },
                    data: [5727.3, 3695.5, 2603.5, 3570, 2986.5, 2365.7, 2261.6, 2137.7, 2179.4, 1542.2],

                },
                {
                    name: '进口额',
                    type: 'bar',
                    itemStyle: {
                        //柱子修改渐变颜色
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#06d680'
                            }, {
                                offset: 1,
                                color: '#56ffd0'
                            }]),

                        }
                    },
                    data: [4781.1, 3276.7, 3567,2270, 2708.8, 2259.8, 2258.8, 2111, 1952.4, 2298.4]
                },
                {
                    name: '贸易额',
                    type: 'line',
                    //symbol:'star',//拐点样式
                    symbolSize: 5*bodyScale,//拐点大小
                    itemStyle: {
                        //线 修改渐变颜色
                        normal: {

                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#e5225a'
                            }, {
                                offset: 1,
                                color: '#ff3f8c'
                            }]),
                            lineStyle: {
                                width: 2*bodyScale,//折线宽度
                                //color:"#000"//折线颜色
                            }

                        }
                    },
                    yAxisIndex: 1,
                    data: [10508.4, 6972.1, 6170.4, 5840, 5695.3, 4625.5, 4520.4, 4248.7, 4131.8, 3840.5]
                }
            ].map(function (item, index) {
                return $.extend(true, {}, com_lineBarSeries, item);
            })
        })
    },

    ec02_line_globe_d() {
        let myChart = echarts.init($("#ec02_line_thecity")[0]);
        myChart.clear();
        myChart.setOption(com_lineBar_vertical);
        myChart.setOption({
            xAxis: [{
                data: ['韩国', '越南', '马来西亚', '印度', '俄罗斯', '泰国', '新加坡', '印度尼西亚', '菲律宾', '沙特阿拉伯'],
            }],
            legend: {show: true,right:'10%',top:0},
            grid:{
                right:'12%',
                left:"8%"
            },
            yAxis : [
                {
                    min: 0,
                    max: 5000,
                    interval: 1000,

                },
                {
                    min: 0,
                    max: 12000,
                    interval: 3000,

                }
            ],
            series: [
                {
                    name: '出口额',
                    type: 'bar',
                    itemStyle: {
                        //柱子修改渐变颜色
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#227cff'
                            }, {
                                offset: 1,
                                color: '#4194ff'
                            }]),
                        }
                    },
                    data: [1029.8, 714.1, 420.2, 683.8, 430.2, 388.1, 454.5, 348.6, 321.3, 183],

                },
                {
                    name: '进口额',
                    type: 'bar',
                    itemStyle: {
                        //柱子修改渐变颜色
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#06d680'
                            }, {
                                offset: 1,
                                color: '#56ffd0'
                            }]),

                        }
                    },
                    data: [1774, 504.7, 542.2, 163.4, 411.7, 417.9, 342.6, 285.2, 192, 317.4]
                },
                {
                    name: '贸易额',
                    type: 'line',
                    //symbol:'star',//拐点样式
                    symbolSize: 5*bodyScale,//拐点大小
                    itemStyle: {
                        //线 修改渐变颜色
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: '#e5225a'
                            }, {
                                offset: 1,
                                color: '#ff3f8c'
                            }]),
                            lineStyle: {
                                width: 2*bodyScale,//折线宽度
                                //color:"#000"//折线颜色
                            }

                        }
                    },
                    yAxisIndex: 1,
                    data: [2803.8, 1218.7, 962.4, 847.2, 841.9, 806, 797.1, 633.8, 513.3, 500.4]
                }
            ].map(function (item, index) {
                return $.extend(true, {}, com_lineBarSeries, item);
            })
        })
    },

    ec03_line_tradetrend_d() {
        let ec03_line = echarts.init($("#ec03_line_tradetrend")[0]);
        ec03_line.setOption(com_line);
        ec03_line.setOption({
            color:['#06d680','#227cff'],
            legend: {show: true,right:'15%',top:0},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid:{
                left:'12%'
            },
            series: [
                {
                    name: '出口额',
                    data: [6980.0, 7737.4, 7520.8, 7134.2, 7742.6]
                },{
                    name: '进口额',
                    data: [7123.1, 7288.9, 6007.2, 5561.6, 6660.6]
                }
               ].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec04_line_exporttrend_d() {
        let ec04_line = echarts.init($("#ec04_line_exporttrend")[0]);
        ec04_line.setOption(com_line);
        ec04_line.setOption({
            legend: {show: true,right:'15%',top:0},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid:{
                left:'12%'
            },
            series: [
                {
                    name: '东部',
                    data: [5196.7, 5699.5,5693.0, 5599.3, 6224.9]
                }, {
                    name: '西部',
                    data: [894.0, 1054.5, 958.0, 753.8, 687.9]
                }, {
                    name: '中部',
                    data: [493.5, 582.5, 575.5, 551.0, 582.0]
                }, {
                    name: '东北',
                    data: [395.7, 401.2, 294.3, 230.1, 247.9]
                },
            ].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec05_line_importtrend_d() {
        let ec05_line = echarts.init($("#ec05_line_importtrend")[0]);
        ec05_line.setOption(com_line);
        ec05_line.setOption({
            legend: {show: true,right:'15%',top:0},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid:{
                left:'12%'
            },
            series: [
                {
                    name: '东部',
                    data: [6059.6, 6074.2, 5011.1, 4566.0, 5269.2]
                },
                {
                    name: '西部',
                    data: [422.5, 555.1, 416.7, 486.8, 746.3]
                },
                {
                    name: '中部',
                    data: [237.4, 252.9, 270.0, 233.2, 276.0]
                },
                {
                    name: '东北',
                    data: [403.7, 406.6, 309.5, 275.6, 369.0]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec06_line_importtrend_d() {
        let ec06_line = echarts.init($("#ec06_line_importtrend")[0]);
        ec06_line.setOption(com_line);
        ec06_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '民营企业',
                    data: [3535.5, 4171.1, 4139.8, 3972.4, 4325.4]
                },
                {
                    name: '外资企业',
                    data: [2420.1, 2515.2, 2398.6, 2236.5, 2420.4]
                },
                {
                    name: '国有企业',
                    data: [1012.6, 1039.4, 967.7, 902.0, 977.0]
                },
                {
                    name: '其他企业',
                    data: [11.7, 11.6, 14.6, 23.3, 19.7]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec07_line_importtrend_d() {
        let ec07_line = echarts.init($("#ec07_line_importtrend")[0]);
        ec07_line.clear();
        ec07_line.setOption(com_line);
        ec07_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '外资企业',
                    data: [2895.5, 2986.5, 2811.4, 2543.8, 2845.5   ]
                },
                {
                    name: '民营企业',
                    data: [1566.7, 1731.9, 1523.2, 1557.5, 1874.3]
                },
                {
                    name: '国有企业',
                    data: [2352.0, 2295.5, 1600.6, 1343.6, 1874.3]
                },
                {
                    name: '其他企业',
                    data: [309.0, 275.0, 72.1, 116.6, 121.9]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec08_line_importtrend_d() {
        let ec08_line = echarts.init($("#ec08_line_importtrend")[0]);
        ec08_line.clear();
        ec08_line.setOption(com_line);
        ec08_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '一般贸易',
                    data: [4236.7, 4775.0, 4667.9, 4398.4, 4751.5]
                },
                {
                    name: '进料加工贸易',
                    data: [1566.2, 1598.5, 1493.3, 1387.5, 1480.4]
                },
                {
                    name: '其他贸易',
                    data: [610.4, 722.4, 804.2, 830.1, 917.8]
                },
                {
                    name: '来料加工装配贸易',
                    data: [267.3, 278.8, 258.2, 262.4, 299.8]
                },
                {
                    name: '边境小额贸易',
                    data: [299.4, 362.6, 297.2, 255.4, 293.1]
                }
                ].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec09_line_importtrend_d() {
        let ec09_line = echarts.init($("#ec09_line_importtrend")[0]);
        ec09_line.clear();
        ec09_line.setOption(com_line);
        ec09_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '一般贸易',
                    data: [3832.2, 3853.2, 2988.1, 2840.9, 3656.1]
                },
                {
                    name: '进料加工贸易',
                    data: [1545.4, 1689.2, 1320.1, 1099.3, 1328.4]
                },
                {
                    name: '其他贸易',
                    data: [1150.9, 1118.6, 1105.0, 1059.4, 1166.9]
                },
                {
                    name: '来料加工装配贸易',
                    data: [459.0, 532.9, 525.6, 494.4, 422.7]
                },
                {
                    name: '边境小额贸易',
                    data: [135.6, 95.0, 68.4, 67.6, 86.4]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec010_line_importtrend_d() {
        let ec010_line = echarts.init($("#ec010_line_importtrend")[0]);
        ec010_line.clear();
        ec010_line.setOption(com_line);
        ec010_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '水路运输',
                    data: [5267.2, 5761.0, 5701.5, 5408.9, 5679.3]
                },
                {
                    name: '航空运输',
                    data: [668.4, 774.0, 808.7, 770.8, 954.3]
                },
                {
                    name: '公路运输',
                    data: [883.8, 1042.8, 865.4, 799.6, 917.7]
                },
                {
                    name: '铁路运输',
                    data: [128.2, 129.9, 107.7, 115.8, 155.7]
                },
                {
                    name: '其他运输',
                    data: [31.7, 27.6, 30.0, 31.3, 30.3]
                },
                {
                    name: '邮件运输',
                    data: [0.8, 2.1, 8.2, 7.8, 5.4]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

    ec011_line_importtrend_d() {
        let ec011_line = echarts.init($("#ec011_line_importtrend")[0]);
        ec011_line.clear();
        ec011_line.setOption(com_line);
        ec011_line.setOption({
            legend:{show:false},
            xAxis: {
                data: ['2013', '2014', '2015', '2016', '2017']
            },
            grid: {
                left: '12%',
                right: '2%',
                bottom: '20%',
            },
            series: [
                {
                    name: '水路运输',
                    data: [4442.6, 4422.5, 3469.8, 3148.2, 3841.9]
                },
                {
                    name: '航空运输',
                    data: [1112.1, 1279.1, 1211.6, 1094.8, 1325.5]
                },
                {
                    name: '公路运输',
                    data: [1059.8, 1042.7, 866.8, 822.2, 1004.9]
                },
                {
                    name: '其他运输',
                    data: [339.0, 367.4, 317.6, 294.3, 349.8]
                },
                {
                    name: '铁路运输',
                    data: [169.3, 176.8, 141.1, 141.7, 138.0]
                },
                {
                    name: '邮件运输',
                    data: [0.4, 0.4, 0.4, 0.4, 0.5]
                }].map(function (item, index) {
                return $.extend(true, {}, com_lineSeries, item);
            })
        });
    },

};
Index.init();


// 获取昨天前天
function getMyDate() {
    let today = new Date();
    let yesterday = new Date(today - 24 * 3600 * 1000);
    let beforeYesterday = new Date(today - 48 * 3600 * 1000);
    [todayDate, yesterdayDate, beforeYesterdayDate, beforeYesterdayDateWithHyphen]
        = [DateFormatter(today).dateStrNoHyphen, DateFormatter(yesterday).dateStrNoHyphen, DateFormatter(beforeYesterday).dateStrNoHyphen, DateFormatter(beforeYesterday).dateStrWithHyphen];
    // 设置油量标题中的前天日期
    let beforeYesterdayObj = DateFormatter(beforeYesterday);
    let [mon, date] = [beforeYesterdayObj.mon, beforeYesterdayObj.date];
    $(".r-b h4").append(`(${mon}月${date}日)`)
}

//初始化时间日期
function initClock() {
    setTimeout(function () {
        let currTime = new Date();
        let [year, mon, date, hour, min, sec, milliSec] = [
            currTime.getFullYear(),
            currTime.getMonth() + 1,
            currTime.getDate(),
            currTime.getHours(),
            currTime.getMinutes(),
            currTime.getSeconds(),
            currTime.getMilliseconds()
        ];
        let time = `${hour}:${min > 9 ? min : "0" + min}:${sec > 9 ? sec : "0" + sec}`;
        let dateStr = `${year}-${mon > 9 ? mon : "0" + mon}-${date > 9 ? date : "0" + date}`;
        $(".time").text(time);
        $(".date").text(dateStr);
        // 调天气预报接口——天气不需要了
        // if (!hasGetWeather) {
        // getWeather(currTime);
        // hasGetWeather = true;
        // } else {
        if (min % getWeatherPeriod === 0 && (sec === 0 || sec === 30) && milliSec < 500) {
            // getWeather(currTime);
            ec02_map_airLines_a(charts.ec02_map_airLines);
            todayFlightPlan();
        }
        // }

        if (hour === 0 && min === 0 && sec === 0 && milliSec < 500) { //过夜
            getDate();
            loadData();
        }
        initClock();
    }, 500)
}




